package com.shadow.controller;

import com.shadow.common.entity.Permission;
import com.shadow.common.entity.User;
import com.shadow.service.PermissionService;
import com.shadow.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by shadow
 * on 2022-6-29.
 */
@Controller
@RequestMapping("/user")
//@SessionAttributes({"sysUser", "isSysPermissionList", "sysPermissionList"})
public class UserController {

    @Resource
    private PermissionService sysPermissionService;
    @Resource
    private UserService sysUserService;

    /**
     * 主页面
     *
     */
    @RequestMapping("/index")
    public String index() {
        return "index/index";
    }

    /**
     * 用户管理
     *
     * 可以手动判断是否拥有权限，也可以通过注解配合ControllerAdvice
     * Subject subject = SecurityUtils.getSubject();
     * subject.isPermitted("用户管理");
     */
    @RequestMapping("/userManage")
    @RequiresPermissions({"用户管理"})
    public String userManage() {
        return "userManage";
    }

    /**
     * 角色管理
     *
     */
    @RequestMapping("/roleManage")
    @RequiresPermissions({"角色管理"})
    public String roleManage() {
        return "roleManage";
    }

    /**
     * 权限管理
     *
     */
    @RequestMapping("/permissionManage")
    @RequiresPermissions({"权限管理"})
    public String permissionManage() {
        return "permissionManage";
    }

    /**
     * 密码修改
     *
     */
    @RequestMapping("/changePassword")
    @RequiresPermissions({"密码修改"})
    public String changePassword() {
        return "changePassword";
    }

}
